package gtfaces;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;

public class TSquareImage {

	public static Collection<TSquareImage> allImages;

	static {
		allImages = new HashSet<TSquareImage>();
	}

	private String image;
	private String studentName;
	private String className;
	private String professorName;

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getStudentName() {
		return studentName;
	}

	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getProfessorName() {
		return professorName;
	}

	public void setProfessorName(String professorName) {
		this.professorName = professorName;
	}

	public TSquareImage(String image, String studentName, String className,
			String professorName) {
		super();
		this.image = image;
		this.studentName = studentName;
		this.className = className;
		this.professorName = professorName;

		// 
		allImages.add(this);
	}

	public Map<String, String> getData() {
		Map<String, String> data = new HashMap<String, String>();
		data.put("username", professorName);
		data.put("class", className);
		data.put("student", studentName);
		data.put("image", image);
		String validate = professorName + "MAS4261";
		try {
			MessageDigest m = MessageDigest.getInstance("MD5");
			m.reset();
			m.update(validate.getBytes());
			byte[] digest = m.digest();
			BigInteger bigInt = new BigInteger(1, digest);
			String hashtext = bigInt.toString(16);
			// Now we need to zero pad it if you actually want the full 32
			// chars.
			while (hashtext.length() < 32)
				hashtext = "0" + hashtext;
			data.put("hash", new String(hashtext));
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return data;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof TSquareImage) {
			TSquareImage img = (TSquareImage) o;
			return this.studentName.equals(((TSquareImage) o).studentName)
					&& this.className == img.className;
		}
		return false;
	}
}
